#include <header.h>
/**
 * 书写程序，创建3个子线程，然后等待所有的子线程终止，
 * 最后获取其退出状态。
*/



/**
 * 究极易错点：如果转成int会报警告，因为64位虚拟机地址时8Byte=64bit
 * 所以强制类型转换时候要转成long
*/

void *run(void *arg){
	
	printf("I am %ld \n", (long)arg);
	return (void*)11;
}


int main(void){

	pthread_t son_thread_1;
	pthread_t son_thread_2;
	pthread_t son_thread_3;

	int retp1 = pthread_create(&son_thread_1, NULL, run, (void*)1); 
	THREAD_ERROR_CHECK(retp1, "thread1");

	int retp2 = pthread_create(&son_thread_2, NULL, run, (void*)2);
	THREAD_ERROR_CHECK(retp2, "thread2");

	int retp3 = pthread_create(&son_thread_3, NULL, run, (void*)3);
	THREAD_ERROR_CHECK(retp3, "thread3");
	
	sleep(3);

	void *ret1, *ret2, *ret3;
	int retj1 = pthread_join(son_thread_1, &ret1);
	THREAD_ERROR_CHECK(retj1, "join 1");
	int retj2 = pthread_join(son_thread_2, &ret2);
	THREAD_ERROR_CHECK(retj2, "join 2");
	int retj3 = pthread_join(son_thread_3, &ret3);
	THREAD_ERROR_CHECK(retj3, "join 3");

	printf("%ld\n", (long)ret1);
	printf("%ld\n", (long)ret2);
	printf("%ld\n", (long)ret3);

	return 0;
}